clear all
set memo 100m
capture log close

local filename GDPResult

log using GDPResult, replace text

local output_dir draft
local output_tex1 `filename'.tex


cd "C:\Users\rujia\Dropbox\\Replication\treatyports"


use data/GDP.dta, clear

keep id year gdp_per  ind_per tindustryper



merge m:1 id using  data/subgroup.dta

drop _m

merge m:1 id using  data/sez.dta

replace sez=0 if sez==.

replace gdp_per=. if ind_per==.|tindustryper==.

gen ln_gdp_per=log(gdp_per)

label var ln_gdp_per "log (GDP per capita)"
label var gdp_per "GDP per capita"
replace coastal2=0 if coastal2==.

drop if year<1987
drop if year>2007
drop if year==1992
drop if year==1993
keep if year==1987|year==1990|year==1995|year==2000|year==2005|year==2007

tabu year, gen(ydummy)
qui tabu id, gen(idummy)

 forvalues i = 1(1)6 {
  gen treaty_d`i'=treatyports*ydummy`i'
}

forvalues x=1(1)6 {
gen latitude_`x'=latitude*ydummy`x'
gen longitude_`x'=longitude*ydummy`x'
gen landtax_`x'=landtax*ydummy`x'
gen silk_`x'=silk*ydummy`x'
gen tea_`x'=tea*ydummy`x'
gen grandcanal_`x'=dis_yunhe*ydummy`x'
gen taipingr_`x'=taipingrrebellion*ydummy`x'

}

forvalues x=1(1)6 {
gen sez_`x'=sez*ydummy`x'
}



local fe "idummy* ydummy*"
local control_fe "latitude_* longitude_* silk_* tea_* grandcanal_* taipingr_* landtax_*"
local sez_fe "sez_*"

label var treaty_d2 "Treatyport*Year1990"
label var treaty_d3  "Treatyport*Year1995"
label var treaty_d4  "Treatyport*Year2000"
label var treaty_d5  "Treatyport*Year2005"
label var treaty_d6  "Treatyport*Year2007"

#delimit ;
eststo clear;

eststo:  regress ln_gdp_per treaty_d2-treaty_d6 `fe', cluster(id);
estadd local fe "Y";
estadd scalar ngrid=e(N_clust);
estadd scalar nobs=e(N);


eststo: qui regress ln_gdp_per treaty_d2-treaty_d6  `fe' `control_fe', cluster(id);
estadd local fe "Y";
estadd local control_fe "Y";
estadd scalar nobs=e(N);
estadd scalar rsquare=e(r2);


eststo:  regress ln_gdp_per treaty_d2-treaty_d6 `fe' `control_fe' `sez_fe', cluster(id);
estadd local fe "Y";
estadd local control_fe "Y";
estadd local sez_fe "Y";
estadd scalar rsquare=e(r2);
estadd scalar nobs=e(N);



eststo: qui regress gdp_per treaty_d2-treaty_d6 `fe', cluster(id);
estadd local fe "Y";
estadd scalar rsquare=e(r2);
estadd scalar nobs=e(N);


eststo:  regress gdp_per treaty_d2-treaty_d6  `fe' `control_fe', cluster(id);
estadd local fe "Y";
estadd local control_fe "Y";
estadd scalar rsquare=e(r2);
estadd scalar nobs=e(N);



eststo:  regress gdp_per treaty_d2-treaty_d6 `fe' `control_fe' `sez_fe', cluster(id);
estadd local fe "Y";
estadd local control_fe "Y";
estadd local sez_fe "Y";
estadd scalar rsquare=e(r2);
estadd scalar nobs=e(N);



esttab using draft/`output_tex1', replace
	width(\hsize) 
	mlabel (, depvar)
	b(3)
	se(3)
	noconstant
	star(* 0.10 ** 0.05 *** 0.01)
	keep(
treaty_d2 
treaty_d3
treaty_d4
treaty_d5
treaty_d6
		)
		
	label
	stats(
		fe
		control_fe
		sez_fe
		 nobs
		 rsquare
		, 
		labels(
			"Prefecture and Year FE" 
			"Controls*Year FE" 
			"SEZs* Year FE"
			"\# observations"
			"R-squared"
			) 
		fmt(0)
		layout(@)
		)
	nonotes
	;
